package com.ruiysoft.entity.logistics.kuaidi100;

import com.alibaba.fastjson.JSON;
import com.ruiysoft.entity.logistics.APILogisticsMessage;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CallbackMessageTool {
    private static Logger logger = LoggerFactory.getLogger(CallbackMessageTool.class);

    public static CallbackMessage toCallbackMessage(String json){
        CallbackMessage callbackMessage = null;
        try {
            if(StringUtils.isNotEmpty(json)) {
                callbackMessage = JSON.parseObject(json, CallbackMessage.class);
            }
        }catch (Exception e){
            logger.error("无法解析json到快递100CallBackMessage类,json为:{}",json);
        }
        return callbackMessage;
    }

    public static APILogisticsMessage toAPILogisticsMessage(CallbackMessage callbackMessage){
        if (callbackMessage == null){
            return null;
        }
        APILogisticsMessage message = new APILogisticsMessage();
        CallbackLastResult lastResult = callbackMessage.getLastResult();
        message.setData(lastResult.getData());
        message.setNu(lastResult.getNu());
        message.setMessage(callbackMessage.getMessage());
        message.setIscheck(lastResult.getIscheck());
        message.setStatus(lastResult.getStatus());
        message.setState(lastResult.getState());
        message.setExpressNO(lastResult.getNu());
        message.setComCode(lastResult.getCom());
        //message.setResult();
        //message.set
        return message;
    }

}
